<?php
/**
 *  💡 免责声明：本软件不得用于商业用途，仅做学习交流
 *  ⚠️ 权利声明：本软件由版权人提供产品技术支持
 *  📅 项目编号：NX2025-0135
 */
namespace App\Admin\Controllers;

use App\Admin\Repositories\SignRule;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Show;

class SignRuleController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new SignRule(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('days');
            $grid->column('reward_points');
            $grid->column('advertisement');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
                $filter->between('created_at', '创建时间')->datetime();
                $filter->between('updated_at', '修改时间')->datetime();
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new SignRule(), function (Show $show) {
            $show->field('id');
            $show->field('days');
            $show->field('reward_points');
            $show->field('advertisement');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new SignRule(), function (Form $form) {
            $form->display('id');
            $form->number('days', '最大签到次数');
            $form->text('reward_points');
            $form->file('advertisement')->threads(5)->maxSize(1024 * 1024)->chunked(1024)->autoUpload();

            $form->display('created_at');
            $form->display('updated_at');
            $form->saved(function (Form $form) {
                return $form->response()->success('操作成功')->redirect(request()->fullUrl() . '/edit');
            });
        });
    }
}
